package com.flex.core.util.file
{
	import flash.events.Event;
	import flash.net.URLRequest;
	import flash.net.URLStream;
	
	import mx.controls.Alert;


	public class FileUtils
	{

		public function FileUtils()
		{
		}

		public function test(e:Event):void
		{
			Alert.show("fileutil read file ok");
		}

		public function readProperty(e:Event):void
		{
			Alert.show("readProperty ok");
//			var baseObj:Object=JSON.decode(xmldata) as Object;
//			var obj:Array=baseObj["mapInfo"];
//			GameConstants.MAP_WRITE_PATH=baseObj["writeMapPath"];
//			for (var i:Number=0; i < obj.length; i++)
//			{
//				var temp:Object=obj[i];
//				GameConstants.BASE_IMG_LIST.addItem(temp);
//			}
		}

		/**
		 * get file info by Loader with URLRequest, may throw error exception,
		 * this function trys to get imageInfo by request,and then dispacth terminal function
		 */
		public static function readFileInfo(filePath:String, fileCompleteEvent:String):void
		{
			try
			{
				var loader:URLStream=new URLStream();
				loader.addEventListener(Event.COMPLETE, function(e:Event):void
				{
					getHttpReq(e, fileCompleteEvent);
				});
				var request:URLRequest=new URLRequest(filePath);
				loader.load(request);
			}
			catch (err:Error)
			{
				Alert.show("property connection error:" + err.message);

			}
		}

		/**
		 * read mapInfo from txt
		 */
		public static function getHttpReq(e:Event, fileCompleteEvent:String):void
		{
			try
			{
				var us:URLStream=e.target as URLStream;
				var xmldata:String=us.readMultiByte(us.bytesAvailable, "UTF-8");
			}
			catch (err:Error)
			{
				Alert.show("request error:" + err.message);
			}
		}
	}
}